﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;

namespace OwinTest.Middleware
{
    public class Test2 : OwinMiddleware
    {
        public Test2(OwinMiddleware next) : base(next)
        {

        }
        public override Task Invoke(IOwinContext context)
        {
            if (context.Request.Path == new PathString("/owin2"))
            {
                var msg = "owin2";
                var msgBytes = Encoding.UTF8.GetBytes(msg);
                context.Response.ContentType = "text/html;charset=utf-8";
                context.Response.Write(msgBytes, 0, msgBytes.Length);
                //解答者告诉Server解答已经完毕,后续Middleware不需要处理
                return Task.FromResult(0);
            }
            //如果不是要处理的路径,那么交付后续Middleware处理
            return Next.Invoke(context);
        }
    }
}
